/*
 * \brief  Support functions for libC back end
 * \author Norman Feske
 * \date   2008-10-23
 */

/*
 * Copyright (C) 2008-2009 Norman Feske
 * Genode Labs, Feske & Helmuth Systementwicklung GbR
 *
 * This file is part of the Genode OS framework, which is distributed
 * under the terms of the GNU General Public License version 2.
 */

/*
 * The debug flag is only usable for building the Linux version of
 * the libC. If enabled, some status output by the back-end functions
 * are printed via the raw_write_str function directly via a Linux
 * system call.
 */
#define DEBUG 0


#if DEBUG
#include <unistd.h>
#include <sys/syscall.h>
#endif /* DEBUG */


/**
 * Write function targeting directly the Linux system call layer and bypassing
 * any libC code.
 */
extern "C" int raw_write_str(const char *str)
{
#if DEBUG
	unsigned len = 0;
	for (; str[len] != 0; len++);
	syscall(SYS_write, (int)1, str, len);
	return len;
#endif /* DEBUG */
}


/**
 * Debug function waiting until the user presses return
 *
 * This function is there to delay the execution of a back-end function such
 * that we have time to attack the GNU debugger to the running process. Once
 * attached, we can continue execution and use 'gdb' for debugging. In the
 * normal mode of operation, this function is never used.
 */
extern "C" void wait_for_continue(void)
{
#if DEBUG
	char buf[16];
	syscall(SYS_read, (int)0, buf, sizeof(buf));
#endif /* DEBUG */
}
